package com.ktkq.service.course.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ktkq.dao.course.CourseMapper;
import com.ktkq.service.course.CourseService;
import com.ktkq.util.PageFinder;
import com.ktkq.util.Pageing;
import com.ktkq.util.TimeUtil;
import com.ktkq.util.font.UploadExcel;
import com.ktkq.vo.Course;


@Service("courseService")
@Transactional
public class CourseServiceImpl implements CourseService{

	@Autowired
	CourseMapper courseMapper;
	
	@Override
	public PageFinder<Course> queryList(Pageing pageing) {
		
		PageFinder<Course> pageFinder = new PageFinder<Course>();
		
		pageFinder.setRowCount(courseMapper.pageCount(pageing));
		pageFinder.setDataList(courseMapper.queryList(pageing));
		
		return pageFinder;
	}

	@Override
	public void insert(Course t) {
		
		courseMapper.insert(t);
	}

	@Override
	public void update(Course t) {
		
		courseMapper.update(t);
	}

	@Override
	public void delete(Course t) {
		
		courseMapper.delete(t);
	}

	@Override
	public List<Course> queryListById(int id) {
		
		return courseMapper.queryById(id);
	}

	@Override
	public List<Course>  UploadExcel(String filePath,Course t) {
		
		List<Course>  lss = new ArrayList<Course>();
	List<List<String>> list = new UploadExcel(filePath).AnalysisExcel();
	 if(list.size()!=0){
		 String time = new TimeUtil().getTime();
		 for(List<String> ls :list){
			 Course course = new Course();			
			 course.setAcademyId(t.getAcademyId());
			 course.setAcademy(t.getAcademy());
			 course.setCourse(ls.get(1));
			 course.setTime(time);
				 lss.add(course);
				 courseMapper.insert(course); 
		 } 
		
	 }
	
	return lss;
	}
	
}
